package com.barry.pattern.dutyList;

import java.util.LinkedList;

public abstract class Officer {
	Duty duty;
	private String name;
	private Officer boss;
	LinkedList<Officer> subordinates = new LinkedList<Officer>();

	protected Officer(String string) {
		this.name=string; 
		setDuty();
	}

	abstract void setDuty();

	protected Duty getDuty() {
		return duty;
	}

	public void addSubordinate(Officer officer) {
		officer.setBoss(this);
		subordinates.add(officer);
	}

	public void removeSubordinates(Officer officer) {
		officer.setBoss(null);
		subordinates.remove(officer);

	}

	/**
	 * @return the boss
	 */
	public Officer getBoss() {
		return boss;
	}

	/**
	 * @param boss the boss to set
	 */
	public void setBoss(Officer boss) {
		this.boss = boss;
	}
	public void getAction(String name, int level) {
		if (level<=getDuty().getGread()) {
			System.err.println(getDuty().getName()+this.name+"批准"+name);
			
		}else {
			if (getBoss()!=null) {
				System.err.println(getDuty().getName()+this.name+"的权限"+getDuty().getGread()+"不够，向上级反映！");
				getBoss().getAction(name, level);
				
			}else {
				System.err.println(name+"的权限要求太高，"+getDuty().getName()+this.name+"表示无能为力！");
			}
		}
	}
	
	
}
